package com.flying.list.exer1;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Random;

public class Test {

    public static void main(String[] args) {

        ArrayList<String> strs = new ArrayList<>();
        Random random = new Random();

        // 向集合中循环加入字符
        for (int i = 0; i < 30; i++) {
            String word = (char) random.nextInt(97, 122)+"";
            strs.add(word);
        }

        System.out.println(Arrays.toString(strs.toArray()));


        int i = ListTest(strs, "a");
        System.out.println("a: "+i);

        int i1 = ListTest(strs, "b");
        System.out.println("b: "+i1);

        int i2 = ListTest(strs, "c");
        System.out.println("c: "+i2);

        int i3 = ListTest(strs, "x");
        System.out.println("x: "+i3);

    }

    public static int ListTest(Collection list, String s){

        int counter=0;
        for (Object o : list) {
            if (o.equals(s)) {
                counter++;
            }
        }
        return counter;
    }
}
